
/**
 * Created by luojie on 2018/3/12.
 * 路由配置。
 */

import React, { Component } from 'react';
import "./css/test.scss";

import api from "./utils/api";

import {HashRouter as Router,Route,Switch,Redirect} from 'react-router-dom';
import Modules from "./entryConfig";

class App extends Component {
    componentWillMount(){
        // let code = getQueryString("code").code;
        this.init();
    }
    async init(){
	    // let code = getQueryString("code").code;
	    // // let code = "001kLjzk06mbxk10smwk0Sx2zk0kLjzU";
	    // let testOpenid = "olsJCwx-pWEkoeIn9Hk4dD8J6SnE";
	    // let openid = getCookie("openid");
	    // if(code){
		 //    let result1 = await ajax(api.getOpenid,{code});
		 //    if(result1.status === 1){
			//     setCookie("openid",result1.datas,7);
		 //    }
	    // }
	    //
	    // let result2 = await ajax(api.getIsLogin,{openid: getCookie("openid")},"post");
	    // if(result2.datas){
		 //    setTimeout(()=>{
			//     window.location.href = `http://www.hugaint.com/H5/activity/index.html#/myMember`;
		 //    },0)
	    // }else{
		 //    setTimeout(()=>{
			//     window.location.href = `http://www.hugaint.com/H5/activity/index.html#/portal`;
		 //    },0)
	    //
	    // }
	    tp.wx.init(
		    {
			    title: '所有的精打细算，都是为爱打算',
			    desc: '成为豆壳终身会员，7700m2教育广场为您服务，享全年首单5折等7重特权……',
			    link: 'http://www.hugaint.com/H5/activity/index2.html',
			    imgUrl: 'http://www.hugaint.com/H5/RecruitStudents_0303/images/icon.jpg',
			    success: function () {
				    ajax("/userInfo/share",{openid:getCookie("openid")},"post")
			    }
		    },
	    );

    }
  render() {
    return (
	    <Router>
            <Switch>
                <Route path = "/portal" component={Modules.Portal}/>
                <Route path = "/login" component={Modules.Login}/>
                <Route path = "/myMember" component={Modules.MyMember}/>
                <Route path = "/luckDraw" component={Modules.luckDraw}/>
                <Route path = "/myGifts" component={Modules.myGifts}/>
                <Route path = "/activityDetail" component={Modules.activityDetail}/>
                <Route path = "/payPage" component={Modules.payPage}/>
                <Route path = "/detail" component={Modules.detail}/>
                <Route path = "/courseList" component={Modules.courseList}/>
                <Route path = "/courseSite" component={Modules.courseSite}/>
	            <Redirect to = "/portal"/>
            </Switch>
        </Router>
    );
  }
}

export default App;
